#include <stdio.h>
#include <unistd.h>

const char *file1 = "/unix-c/apue.c";
const char *file2 = "/unix-c/apuc.cpp";

#define FILE_EXIST(f) access((f), F_OK)
#define FILE_WROK(f) access((f), W_OK)
#define FILE_RDOK(f) access((f), R_OK)
#define FILE_EXECOK(f) access((f), X_OK)


int main() {
    const char *pfiles[] = { file1, file2 };
    const char **p = pfiles;
    int n = 2;

    while(n--) {
        if (FILE_EXIST(*p)) {
            printf("%s is exist\n", *p);
            if(FILE_WROK(*p))
                printf("%s is writeable\n", *p);
            if(FILE_RDOK(*p))
                printf("%s is readable\n", *p);
            if(FILE_EXECOK(*p))
                printf("%s is executable\n", *p);
        } else {
            printf("%s is not exist\n", *p);
        }
        p++;
    }

    return 0;
}
